﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

#nullable disable

namespace Css_VoteSys.Models.Database
{
    public partial class Css_VoteSysContext : DbContext
    {
        public Css_VoteSysContext()
        {
        }

        public Css_VoteSysContext(DbContextOptions<Css_VoteSysContext> options)
            : base(options)
        {
        }

        public virtual DbSet<Award> Awards { get; set; }
        public virtual DbSet<AwardCategory> AwardCategories { get; set; }
        public virtual DbSet<Category> Categories { get; set; }
        public virtual DbSet<Company> Companies { get; set; }
        public virtual DbSet<Privilege> Privileges { get; set; }
        public virtual DbSet<User> Users { get; set; }
        public virtual DbSet<VoteInfo> VoteInfos { get; set; }
        public virtual DbSet<VoteProject> VoteProjects { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
                optionsBuilder.UseSqlServer("Data Source=112.74.78.185;Initial Catalog=Css_VoteSys;User ID=sa;Password=MSSQL@12345");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasAnnotation("Relational:Collation", "Chinese_PRC_CS_AI_WS");

            modelBuilder.Entity<Award>(entity =>
            {
                entity.ToTable("Award");

                entity.Property(e => e.Year).HasColumnType("date");
            });

            modelBuilder.Entity<AwardCategory>(entity =>
            {
                entity.ToTable("AwardCategory");

                entity.Property(e => e.AwardCategoryName)
                    .IsRequired()
                    .HasMaxLength(50);
            });

            modelBuilder.Entity<Category>(entity =>
            {
                entity.ToTable("Category");

                entity.Property(e => e.CategoryName)
                    .IsRequired()
                    .HasMaxLength(50);
            });

            modelBuilder.Entity<Company>(entity =>
            {
                entity.ToTable("Company");

                entity.Property(e => e.CompanyLogo).HasMaxLength(100);

                entity.Property(e => e.CompanyName)
                    .IsRequired()
                    .HasMaxLength(50);
            });

            modelBuilder.Entity<Privilege>(entity =>
            {
                entity.ToTable("Privilege");

                entity.Property(e => e.PrivilegeName)
                    .IsRequired()
                    .HasMaxLength(50);
            });

            modelBuilder.Entity<User>(entity =>
            {
                entity.ToTable("User");

                entity.Property(e => e.Email)
                    .IsRequired()
                    .HasMaxLength(50);

                entity.Property(e => e.Password)
                    .IsRequired()
                    .HasMaxLength(50);

                entity.Property(e => e.PrivilegeId).HasComment("用户权限id");

                entity.Property(e => e.Salt)
                    .IsRequired()
                    .HasMaxLength(20)
                    .IsUnicode(false);
            });

            modelBuilder.Entity<VoteInfo>(entity =>
            {
                entity.HasKey(e => new { e.UserId, e.ProjectId })
                    .HasName("PK__VoteInfo__00E967A3A2C40246");

                entity.ToTable("VoteInfo");

                entity.Property(e => e.VoteId).ValueGeneratedOnAdd();

                entity.Property(e => e.VoteTime).HasColumnType("date");
            });

            modelBuilder.Entity<VoteProject>(entity =>
            {
                entity.HasKey(e => e.ProjectId)
                    .HasName("PK__VoteProj__761ABEF01961BFD7");

                entity.Property(e => e.Description)
                    .IsRequired()
                    .HasMaxLength(200);

                entity.Property(e => e.ImageUrl).HasMaxLength(200);

                entity.Property(e => e.IsShow).HasComment("是否展示（0不展示 1展示）");

                entity.Property(e => e.Title)
                    .IsRequired()
                    .HasMaxLength(100);
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
